<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
	$(function(){
		$("#list").click(function(){
			location.href="${initParam.root }/board_newslist.do";
		});
		$("#update").click(function(){
			if(confirm("수정 하시겠습니까?")){
			location.href="${initParam.root}/board_newsUpdateView.do?&no=${requestScope.map.bvo.no}";
			}else{
				return false;
			}
		});
		$("#delete").click(function(){
			if(confirm("삭제 하시겠습니까?")){
			location.href="news_deleteReply.do?&no=${requestScope.map.bvo.no}";
			}else{
				return false;
			}
		});
		$("#replyContent").click(function(){
			$("#replyContent").html("");
			$("#reply_write_btn").click(function(){
				location.href="${initParam.root}/reply_newsWirte.do?&boardVO.no=${requestScope.map.bvo.no}&memberVO.id=${sessionScope.mvo.id}&rcontent="+$("#replyContent").val();
			});
		});
		$(":input[name=re_delete_btn]").click(function(){
			if(confirm("삭제 하시겠습니까?")){
				location.href="${initParam.root}/news_deleteReply.do?rno="+$(this).next().val()+"&refno=${requestScope.map.bvo.no}&id=${sessionScope.mvo.id}";
			}else{
				return false;
			}
		});
	
		// 댓글 수정
		$(":input[name=re_update_btn]").click(function(){
				//alert($(this).next().val());
				//alert($(this).next().next().val());
			 var no = $(this).next().val();
			$("#editReplyDialog").html("<input type=text id=updateReplyContent value="+$(this).next().next().val()+">").dialog({
				resizable:false,
				height:200,
				modal:true,
				buttons: {
					'수정':function() {
						//alert(no);
						//alert($("#updateReplyContent").val());
						location.href="${initParam.root}/news_updateReply.do?rno="+no+"&boardVO.no="+$("#bno").val()+"&rcontent="+$("#updateReplyContent").val();
					},
					'취소':function() {
						$(this).dialog('close');
					}//function
				}//button
			});//dialog 
		});//click
		
 	$(":input[name=restep]").click(function() {
			//alert($(this).next().val());
			var ref=$(this).next().val();
			$("#reReplyDialog").html("<input type=text id=reReplyContent>").dialog({
				resizable:false,
				height:200,
				modal:true,
				buttons: {
					'덧글':function() {
						//alert(no);
						//alert($("#updateReplyContent").val());
						location.href="${initParam.root}/news_reReply.do?ref="+ref+"&boardVO.no="+$("#bno").val()+"&rcontent=→"+$("#reReplyContent").val()+"&memberVO.id=${sessionScope.mvo.id}";
					},
					'취소':function() {
						$(this).dialog('close');
					}//function
				}//button
			});//dialog 
		});
	});
</script>
<center>
<input type="text" name="no" value="${requestScope.map.bvo.no }" readonly="readonly" size="2" >
<input type="text" name="title" value="${requestScope.map.bvo.title }" readonly="readonly" size="5">
<input type="text" name="writer" value="${requestScope.map.bvo.memberVO.id }" readonly="readonly" size="6">
<input type="text" name="writedate" value="${requestScope.map.bvo.writedate }" readonly="readonly">
<input type="text" name="count" value="${requestScope.map.bvo.count }" size="2"><br>
<textarea rows="10" cols="56" readonly="readonly">${requestScope.map.bvo.content }</textarea><br>
<input type="button" id="list" value="목록보기">

<c:if test="${sessionScope.mvo!=null}">
	<c:if test="${sessionScope.mvo.id==requestScope.map.bvo.memberVO.id}">
<input type="button" id="update" value="수정">
<input type="button" id="delete" value="삭제">
	</c:if>
</c:if>
<br><br>
<textarea rows="2" cols="40"  id="replyContent" style="resize:none">댓글을 입력해 주세요</textarea><input type="button" id="reply_write_btn" value="확인">
<!-- 현재 보이는 게시글 번호 -->
<input type="hidden" value="${requestScope.map.bvo.no }" id="bno">
<br>

<table cellpadding="2" width="35%">
<c:forEach items="${requestScope.map.list }" var="list">
<tr>
<td align="center" width="25">${list.memberVO.id}</td>
<td width="10%"></td>
		<td width="60%">${list.rcontent }</td>
		
		<td align="right" ><input type="button" name="restep" value="답글">
		<input type="hidden" name="ref" value="${list.rno }">
			<c:if test="${sessionScope.mvo.id==list.memberVO.id}">
				<input type="hidden" name="rno" value="${list.rno}">
					<td><input type="button" name="re_delete_btn" value="삭제">
					<input type="hidden" name="rno" value="${list.rno}">
					</td>
					<td><input type="button" name="re_update_btn" value="수정">
					<input type="hidden" name="rno" value="${list.rno}">
					<input type="hidden" name="rno" value="${list.rcontent}">
					</td>
			</c:if>
	

	</td>
</tr>
</c:forEach>
</table>
<!-- 댓글 수정 (다이얼로그) -->
<div id="editReplyDialog" title="코멘트 수정"></div>
<!-- 댓글 댓글 (다이얼로그) -->
<div id="reReplyDialog" title="답 코멘트"></div>

</center>